package com.dyz.swordFingerOffer;

/**
 * @author: daiyizheng
 * @date: 2021/6/9 21:16
 * @description:
 */
public class IsBalanced_Solution55 {
    private boolean flag = true;
    public boolean IsBalanced_Solution(TreeNode root) {
        if(root==null){
            return true;
        }
        TreeDepth(root);
        return flag;
    }

    private int TreeDepth(TreeNode root){
        if (root==null){
            return 0;
        }

        int left = TreeDepth(root.left);
        int right = TreeDepth(root.right);

        if(Math.abs(left-right)>1){//二叉树的任何节点都满足平衡二叉树
            flag = false;
        }
        return Math.max(left, right)+1;
    }
}
